// 模拟商品详情数据
const productData = {
    title: "Air Jordan 6 Rings出租车",
    price: 1599.00,
    probability: "1.59%",
    rarity: "史诗",
    rarityTag: "epic",
    guarantee: "全新正品・假一赔三・超时赔付",
    cover: "https://picsum.photos/200/200?20",
    detailsImages: [
        "https://picsum.photos/200/200?20",
        "https://picsum.photos/200/200?20",
        "https://picsum.photos/200/200?20"
    ]
};
function goTo(path) {
    if (document.referrer && document.referrer !== window.location.href) {
        window.history.back(); // 返回上一页
    } else {
        window.location.href = path; // 没有来源页就跳转到给定 path，比如首页
    }
}

// 渲染函数
function renderProductDetail(data) {
    // 封面图
    const imageDiv = document.querySelector(".product-image");
    imageDiv.style.backgroundImage = `url('${data.cover}')`;

    // 商品基本信息
    document.querySelector(".price strong").textContent = `¥${data.price.toFixed(2)}`;
    document.querySelector(".probability").textContent = `概率${data.probability}`;
    document.querySelector(".product-name").innerHTML = `
    <span class="tag ${data.rarityTag}">${data.rarity}</span>
    ${data.title}
  `;

    // 商品详情图
    const detailsContainer = document.querySelector(".details-img-list");
    detailsContainer.innerHTML = data.detailsImages.map(url => `
    <img src="${url}" alt="商品详情图" />
  `).join("");
}

// 关闭按钮事件
// document.getElementById("closeBtn").addEventListener("click", () => {
//     goTo("index.html");
// });


// 初始化渲染
document.addEventListener("DOMContentLoaded", () => {
    renderProductDetail(productData);
});

document.addEventListener("DOMContentLoaded", () => {
    renderProductDetail(productData);

    const scrollArea = document.querySelector(".scrollable-content");
    const header = document.querySelector(".modal-header");
    let lastScrollTop = 0;

    scrollArea.addEventListener("scroll", () => {
        const currentScroll = scrollArea.scrollTop;
        if (currentScroll > lastScrollTop) {
            header.classList.add("hide-header"); // 向下滚动 -> 隐藏
        } else {
            header.classList.remove("hide-header"); // 向上滚动 -> 显示
        }
        lastScrollTop = currentScroll <= 0 ? 0 : currentScroll;
    });
});

